package v3


import InputField
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.TabRowDefaults.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import java.math.BigDecimal
import java.math.RoundingMode

@Composable
fun LiRunCompose3(
    modifier: Modifier = Modifier.padding(8.dp)
) {
    var chengben by remember { mutableStateOf("") }
    var shoujia by remember { mutableStateOf("") }
    var bili by remember { mutableStateOf("") }
    var lirun by remember { mutableStateOf("") }

    Row(modifier = modifier.fillMaxWidth()) {
        Column(modifier = Modifier.weight(1f)) {
            InputField("成本价", chengben) { chengben = it }
            Spacer(modifier = Modifier.height(8.dp))
            InputField("售价", shoujia) { shoujia = it }
            Spacer(modifier = Modifier.height(8.dp))
            InputField("广告比例(%)", bili) { bili = it }

            Spacer(modifier = Modifier.height(8.dp))

            Button(onClick = {
                if (chengben.isNotBlank() && shoujia.isNotBlank() && bili.isNotBlank()) {
                    val chengbenValue = BigDecimal(chengben)
                    val shoujiaValue = BigDecimal(shoujia)
                    val biliValue = BigDecimal(bili).divide(BigDecimal(100), 10, RoundingMode.HALF_UP)

                    val computedLirun = (shoujiaValue * (BigDecimal.ONE + biliValue)) - chengbenValue
                    lirun = computedLirun.setScale(6, RoundingMode.HALF_UP)
                        .stripTrailingZeros()
                        .toPlainString()
                }
            }) {
                Text("计算")
            }

            Spacer(modifier = Modifier.height(8.dp))
            Text("利润：$lirun")
        }

        Divider(
            color = Color.Gray,
            thickness = 1.dp,
            modifier = Modifier
                .width(2.dp)
                .fillMaxHeight()
                .padding(horizontal = 8.dp)
        )

        Column(modifier = Modifier.weight(1f)) {
            Text("历史记录")
        }
    }
}

